<?php

declare(strict_types=1);

namespace SixShop\Wangdian\Services;

use SixShop\Wangdian\Response\ApiResponse;

/**
 * Trade service for orders, logistics sync, etc.
 */
class TradeService extends BaseService
{
    /**
     * Push trade information
     */
    public function push(array $tradeData): ApiResponse
    {
        $this->validateRequired($tradeData, ['shop_no', 'trade_list']);

        return $this->call('trade_push.php', [
            'shop_no' => $tradeData['shop_no'],
            'switch' => $tradeData['switch'] ?? 0,
            'trade_list' => $this->encodeIfArray($tradeData['trade_list']),
        ]);
    }

    /**
     * Query trade information
     */
    public function query(array $params = []): ApiResponse
    {
        return $this->call('trade_query.php', $this->filterParams($params));
    }

    /**
     * Query logistics sync information
     */
    public function queryLogisticsSync(array $params = []): ApiResponse
    {
        return $this->call('logistics_sync_query.php', $this->filterParams($params));
    }

    /**
     * Acknowledge logistics sync
     */
    public function ackLogisticsSync(array $logisticsList): ApiResponse
    {
        return $this->call('logistics_sync_ack.php', [
            'logistics_list' => $this->encodeIfArray($logisticsList),
        ]);
    }

    /**
     * Query goods stock change
     */
    public function queryGoodsStockChange(array $params = []): ApiResponse
    {
        return $this->call('api_goods_stock_change_query.php', $this->filterParams($params));
    }

    /**
     * Acknowledge goods stock change
     */
    public function ackGoodsStockChange(array $changeIds): ApiResponse
    {
        $this->validateRequired(['change_ids' => $changeIds], ['change_ids']);

        return $this->call('api_goods_stock_change_ack.php', [
            'change_ids' => $this->encodeIfArray($changeIds),
        ]);
    }

    /**
     * Query stockout orders for trade
     */
    public function queryStockoutOrder(array $params = []): ApiResponse
    {
        return $this->call('stockout_order_query_trade.php', $this->filterParams($params));
    }
}